<template>
  <div class="back">
    <el-form
      ref="ruleFormRef"
      class="form"
      label-position="left"
      :model="form"
      :rules="rules"
    >
      <p class="title">×××数据巡检后台管理</p>
      <el-form-item prop="username">
        <el-input
          v-model="ruleForm.username"
          placeholder="请输入管理员账号"
        ></el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input
          v-model="ruleForm.password"
          placeholder="请输入管理员密码"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" style="width: 60%" @click="onSubmit"
          >登陆</el-button
        >
        <el-button type="primary" @click="goHead">返回前台</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup>
import { ElMessage } from "element-plus";
import { reactive, ref } from "vue";
import { useRouter } from "vue-router";
const $router = useRouter();
//弹出提示
const open2 = () => {
  ElMessage({
    message: "账号密码有误",
    type: "error",
  });
};
//定义账号密码
const ruleForm = reactive({
  username: "",
  password: "",
});
//登陆（比对账号密码）
function onSubmit() {
  if (ruleForm.username == "admin" && ruleForm.password == "123456") {
    $router.push({
      path: "/home/over-view",
    });
    localStorage.setItem("user", ruleForm.username);
  } else {
    ruleForm.username = "";
    ruleForm.password = "";
    open2();
  }
}
//返回前台
function goHead() {
  $router.push({
    path: "/net",
  });
}
</script>

<style lang="scss" scoped>
.form {
  display: block;
  width: 20%;
  position: absolute;
  top: 30%;
  left: 40%;
}
.form .title {
  text-align: center;
  font-size: 1.5em;
  color: #fff;
  margin-bottom: 20px;
}
.back {
  height: 100vh;
  background-image: linear-gradient(125deg, #002c9b, #000a24);
  background-size: 500%;
  animation: animate 20s infinite;
}
@keyframes animate {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}
</style>